from PySide2 import QtWidgets
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication, QMessageBox, QLabel, QMainWindow,QPlainTextEdit
import numpy as np
import pyqtgraph as pg




class MainWindow(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.window = QMainWindow()
        # self.window.resize(250, 200)  # 设置Window大小
        # self.window.move(300, 300)
        #self.ui = QUiLoader().load('ui/graphics.ui')


        self.XTextEdit= QtWidgets.QPlainTextEdit(self)
        self.YTextEdit = QtWidgets.QPlainTextEdit(self)
        self.XtilTextEdit = QtWidgets.QPlainTextEdit()
        self.YtilTextEdit = QtWidgets.QPlainTextEdit()
        self.TitleEdit = QtWidgets.QPlainTextEdit()


        ColorboBox=QtWidgets.QComboBox()
        LineboBox = QtWidgets.QComboBox()
        SymbolboBox = QtWidgets.QComboBox()
        ColorboBox.addItems(['蓝色', '黑色', '绿色', '黄色', '红色', '白色', '洋红色', '青绿色'])
        LineboBox.addItems(['实线','虚线','点划线','破折线'])
        SymbolboBox.addItems(['无标记','圆点','圆圈','向下三角形','向上三角形','向左三角形','向右三角形','五角星形','加号','下划线','x符号','菱形'])


        #self.ui.pushButton.clicked.connect(self.Plot_line)

    def Plot_line(self):
        #颜色选择后续可改用色盘
        Line_Color = {'蓝色': 'b', '黑色': 'k', '绿色': 'g', '黄色': 'y', '红色': 'r', '白色': 'w', '洋红色': 'm',
                      '青绿色': 'c'}
        Line_type={'实线':'-','虚线':':','点划线':'-.','破折线':'--'}
        Symbol_mark={'无标记':'','圆点':'.','圆圈':'o','向下三角形':'v','向上三角形':'^','向左三角形':'<','向右三角形':'>','五角星形':'*','加号':'+',
                     '下划线':'_','x符号':'x','菱形':'D'}
        Color_text = self.ui.ColorboBox.currentText()
        Line_text=self.ui.LineboBox.currentText()
        Symbol_text=self.ui.SymbolboBox.currentText()
        Line_shape=Line_Color[Color_text]+Line_type[Line_text]+Symbol_mark[Symbol_text]

        Plot_title=self.ui.TitleEdit.toPlainText()
        Xplot_title = self.ui.XtilTextEdit.toPlainText()
        Yplot_title = self.ui.YtilTextEdit.toPlainText()

        xpoint = self.ui.XTextEdit.toPlainText()
        ypoint = self.ui.YTextEdit.toPlainText()
        xpoints = np.array(list(map(int,xpoint.split( ))))
        ypoints = np.array(list(map(int,ypoint.split( ))))

        if xpoint and ypoint != '':
            self.pw=pg.PlotWidget()
            self.pw.setTitle(Plot_title,color='008080',size='12pt')
            self.pw.setLabel("left",Yplot_title)
            self.pw.setLabel("bottom", Xplot_title)
            self.pw.setBackground('w')#默认背景是黑色
            self.pw.plot(xpoints,ypoints,Line_Color[Color_text])

            Tlabel=self.ui.label_3()
            Mainchioce=self.ui.gridLayout.QGridLayout()
            Bottombutton=self.ui.horizontalLayout_3.QHBoxLayout()

            Lbox=QtWidgets.QHBoxLayout()
            Lbox.addWidget(Tlabel,Mainchioce,Bottombutton)

            Abox = QtWidgets.QVBoxLayout()
            Abox.addWidget(self.pw)
            Abox.setLayout(Lbox)

            self.setLayout(Abox)

            # [1, 8], [3, 10]  # (1,3)-(8,10)
        else:  # x或y孔
            QMessageBox.warning(
                self.ui,
                '坐标错误',
                '请输入完整的x和y坐标')




if __name__ == "__main__":
    app =QApplication([])
    # 实例化窗口
    mainwindow = MainWindow()
    mainwindow.window.show()

    app.exec_()
